﻿using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace InvestmentIntelligence.DbModel.Models.Mapping
{
    public class InvestmentRiskSerieMap : EntityTypeConfiguration<InvestmentRiskSerie>
    {
        public InvestmentRiskSerieMap()
        {
            // Primary Key
            this.HasKey(t => new { t.InvestmentId, t.Date });

            // Properties
            this.Property(t => t.InvestmentId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
            
            // Table & Column Mappings
            this.ToTable("InvestmentRiskSerie", "Analytics");
            this.Property(t => t.InvestmentId).HasColumnName("InvestmentId");
            this.Property(t => t.Date).HasColumnName("Date");
            this.Property(t => t.Risk).HasColumnName("Risk").HasPrecision(29, 20);
            
            this.HasRequired(t => t.Investment)
                .WithMany(t => t.RiskSeries)
                .HasForeignKey(d => d.InvestmentId);
        }
    }
}
